package com.cbgolf.oa.adapter.recycle;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.cbgolf.oa.R;
import com.cbgolf.oa.adapter.recycle.StatisticsDetailsAdapter.Holder;
import com.cbgolf.oa.entity.GoodsBean;
import com.cbgolf.oa.entity.ListBean;
import com.cbgolf.oa.entity.ListBean.CashWay;
import com.cbgolf.oa.entity.ListBean.Customer;
import com.cbgolf.oa.entity.ListBean.CustomerItemInfo;
import com.cbgolf.oa.entity.ListBean.PayInfo;
import com.cbgolf.oa.entity.ListBean.ReserveInfo;
import com.cbgolf.oa.entity.ListBean.Teetime;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.manager.OrderManager;
import com.cbgolf.oa.util.DateUtil;
import com.cbgolf.oa.util.DensityUtil;
import com.cbgolf.oa.util.ScreenUtil;
import com.cbgolf.oa.util.TextUtil;
import com.cbgolf.oa.util.TypeUtil;
import com.cbgolf.oa.util.Util;
import com.cbgolf.oa.util.ViewUtils;
import com.cbgolf.oa.views.ErrorView;
import com.cbgolf.oa.widget.RecyclerItemDecoration;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lq
 * @date 2018/5/7
 */

public class StatisticsDetailsAdapter extends RecyclerView.Adapter<Holder> {


  private List<ListBean> list;
  private String orderType;
  private Context context;
  private LayoutInflater mInflater;

  private int mType;


  public StatisticsDetailsAdapter(Context context, int type) {
    this.context = context;
    mType = type;
    mInflater = LayoutInflater.from(context);
  }

  public void setData(List<ListBean> list) {
    this.list = list;
    notifyDataSetChanged();
  }

  public void addAll(List<ListBean> list) {
    if (null == this.list) {
      this.list = new ArrayList<>();
    }
    if (!Util.listIsNull(list)) {
      this.list.addAll(list);
    }
    notifyDataSetChanged();
  }

  public void setData(List<ListBean> list, String orderType) {
    this.list = list;
    this.orderType = orderType;
    notifyDataSetChanged();
  }

  @NonNull
  @Override
  public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    Holder holder = null;
    switch (mType) {
      case DataManager.STATISTICS_BILL_ALL:
      case DataManager.STATISTICS_PLAYER_ALL:
      case DataManager.STATISTICS_BUSINESS_ALL:
        holder = getStatisticsPlayerDetailsHolder(viewType);
        break;
      case DataManager.STATISTICS_BOOK_ALL:
        holder = getStatisticsBookDetailsHolder(viewType);
        break;
      case DataManager.STATISTICS_CADDIE_ALL:
        holder = getStatisticsCaddieDetailsHolder(viewType);
        break;
      default:
        break;
    }
    return holder;
  }

  private Holder getStatisticsCaddieDetailsHolder(int viewType) {
    Holder holder;
//    if (viewType == getItemCount() - 1) {
//      holder = new RemarkHolder(mInflater.inflate(R.layout.include_remark, null));
//    } else {
//      holder = new CaddieListHolder(
//          mInflater.inflate(R.layout.item_rcy_caddie_details, null));
//    }
    holder = new CaddieListHolder(
        mInflater.inflate(R.layout.item_rcy_caddie_details, null));
    return holder;
  }

  private Holder getStatisticsBookDetailsHolder(int viewType) {
    Holder holder = null;
    switch (viewType) {
      case 0:
        holder = new HeaderBookHolder(
            mInflater.inflate(R.layout.include_recycleview, null));
        break;
      case 1:
        holder = new BillDetailsHolder(mInflater.inflate(R.layout.inclue_play_ball_details, null));
        break;
      case 2:
        holder = new PayDetailsHolder(mInflater.inflate(R.layout.include_recycleview, null));
        break;
      case 3:
        holder = new RemarkHolder(mInflater.inflate(R.layout.include_remark, null));
        break;
      default:
        break;
    }
    return holder;
  }

  @SuppressLint("InflateParams")
  private Holder getStatisticsPlayerDetailsHolder(int viewType) {
    Holder holder = null;
    switch (viewType) {
      case 0:
        holder = new HeaderMsgHolder(
            mInflater.inflate(R.layout.inclue_public_statistics_listdetails_msg, null));
        break;
      case 1:
        holder = new TeetimeDetailsHolder(
            mInflater.inflate(R.layout.inclue_play_ball_details, null));
        break;
      case 2:
        holder = new BillDetailsHolder(mInflater.inflate(R.layout.inclue_play_ball_details, null));
        break;
      case 3:
        holder = new PayDetailsHolder(mInflater.inflate(R.layout.include_recycleview, null));
        break;
      case 4:
        holder = new RemarkHolder(mInflater.inflate(R.layout.include_remark, null));
        break;
      default:
        break;
    }
    return holder;
  }

  @Override
  public void onBindViewHolder(@NonNull Holder holder, int position) {
    if (!Util.listIsNull(list)) {
      holder.bindData(list.get(position));
    }
  }

  @Override
  public int getItemViewType(int position) {
    return position;
  }


  @Override
  public int getItemCount() {
    return Util.listIsNull(list) ? 0 : list.size();
  }

  static abstract class Holder extends RecyclerView.ViewHolder {

    public Holder(View itemView) {
      super(itemView);
    }

    protected abstract void bindData(ListBean data);
  }

  /**
   * 头部公共信息
   */

  public class HeaderMsgHolder extends Holder {

    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.tv_date)
    TextView dateTv;
    @BindView(R.id.tv_cardnum)
    TextView carkNumTv;
    @BindView(R.id.tv_name)
    TextView nameTv;
    @BindView(R.id.tv_id)
    TextView idTv;
    @BindView(R.id.tv_locker_num)
    TextView lockerNumTv;
    @BindView(R.id.tv_ballpackage_num)
    TextView ballPackageTv;
    @BindView(R.id.tv_playnum_tag)
    TextView playNumTagTv;
    @BindView(R.id.tv_playnum)
    TextView playNumTv;
    @BindView(R.id.ll_playnum)
    View playNumView;
    @BindView(R.id.tv_state)
    TextView stateTv;


    public HeaderMsgHolder(View itemView) {
      super(itemView);
      ButterKnife.bind(this, itemView);
      ViewUtils.setLayoutParams(layout, ScreenUtil.getWidth(), LayoutParams.WRAP_CONTENT);
    }

    @Override
    protected void bindData(ListBean data) {
      if (null == data) {
        return;
      }
      if (mType == DataManager.STATISTICS_BILL_ALL) {
        ViewUtils.setText(dateTv, DateUtil.stampToDate(data.recordDate));
        ViewUtils.setText(carkNumTv, data.consumerCardNo);
        ViewUtils.setText(nameTv, data.name);
        ViewUtils.setText(idTv, data.identityName);
        ViewUtils.setText(lockerNumTv, data.lockerNo);
        ViewUtils.setText(stateTv,
            Util.isEquals(data.status, "PAIED") ? "已结帐" : "未结帐");
        ViewUtils
            .setText(ballPackageTv, data.bagNumber);
        ViewUtils.setText(playNumTagTv, "击球洞数");
        ViewUtils.setText(playNumTv, data.ballCave);
        return;
      }
      if (null == data.customerInfoDto) {
        return;
      }
      ViewUtils.setText(dateTv, DateUtil.stampToDate(data.customerInfoDto.recordDateTime));
      ViewUtils.setText(carkNumTv, data.customerInfoDto.consumerCard);
      ViewUtils.setText(nameTv, data.customerInfoDto.name);
      ViewUtils.setText(idTv, data.customerInfoDto.identifyName);
      ViewUtils.setText(lockerNumTv, data.customerInfoDto.lockerno);
      switch (mType) {
        case DataManager.STATISTICS_PLAYER_ALL:
          ViewUtils.setText(stateTv,
              Util.isEquals(data.customerInfoDto.play, true) ? "下场" : "未下场");
          break;
        case DataManager.STATISTICS_BUSINESS_ALL:
          ViewUtils.setText(stateTv,
              Util.isEquals(data.customerInfoDto.cashStatus, true) ? "已结帐" : "未结帐");
          break;
        default:
          break;
      }
      ViewUtils
          .setText(ballPackageTv, TextUtil.Text(data.customerInfoDto.bagnumber, TextUtil.TAGNULL));
      ViewUtils.setText(playNumTagTv, "击球洞数");
      ViewUtils.setText(playNumTv, TextUtil.textNumInt(data.customerInfoDto.openBallCave));
    }
  }

  /**
   * 球僮列表
   */

  public class CaddieListHolder extends Holder {

    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.g_error_ll)
    View errorLayout;
    @BindView(R.id.g_error_layout_ll)
    View errorView;
    @BindView(R.id.g_error_tv)
    TextView errorTv;
    @BindView(R.id.g_error_logo_iv)
    ImageView logoIv;

    @BindView(R.id.tv_teetime)
    TextView teeTimeTv;
    @BindView(R.id.tv_playernum)
    TextView playerNumTv;

    @BindView(R.id.recycleView)
    RecyclerView recyclerView;

    public CaddieListHolder(View itemView) {
      super(itemView);
      ButterKnife.bind(this, itemView);
    }

    @Override
    protected void bindData(ListBean data) {
      if (null == data) {
        return;
      }
      ViewUtils.setText(teeTimeTv, data.teeTimeInfo);
      ViewUtils.setText(playerNumTv, data.singleDoubleBag);
      if (data.isNoData && list.size() == 1) {
        ViewUtils.setVisible(layout, false);
        ViewUtils.setVisible(errorLayout, true);
        ViewUtils.setText(errorTv, data.noDataText);
        ViewUtils.setImage(logoIv, ErrorView.getLogoRes(data.errorCode));
        ViewUtils.setLayoutParams(errorView, ScreenUtil.getWidth(),
            ScreenUtil.getHeight() - DensityUtil.dip2px(context, 48));
        return;
      }
      ViewUtils.setLayoutParams(layout, ScreenUtil.getWidth(), LayoutParams.WRAP_CONTENT);
      ViewUtils.setVisible(errorLayout, false);
      ViewUtils.setVisible(layout, true);
      CommonAdapter<Customer> adapter = new CommonAdapter<Customer>(context,
          R.layout.item_user_card,
          data.customers) {
        @Override
        protected void convert(ViewHolder holder, Customer bean, int position) {
          if (null == bean) {
            return;
          }
          holder.setText(R.id.tv_cardno, TextUtil.Text(bean.consumerCar))
              .setText(R.id.tv_player, TextUtil.Text(bean.name))
              .setText(R.id.tv_id, TextUtil.Text(bean.identityName))
              .setText(R.id.tv_hole, TextUtil.Text(bean.openBallCave));
        }
      };
      LinearLayoutManager lm = new LinearLayoutManager(context);
      lm.setOrientation(LinearLayoutManager.VERTICAL);
      recyclerView.addItemDecoration(new RecyclerItemDecoration(1, 0, 0, 0));
      recyclerView.setLayoutManager(lm);
      recyclerView.setHasFixedSize(true);
      recyclerView.setAdapter(adapter);
    }
  }

  /**
   * 预订 头部公共信息
   */

  public class HeaderBookHolder extends Holder {

    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.recycleView)
    RecyclerView recyclerView;

    public HeaderBookHolder(View itemView) {
      super(itemView);
      ButterKnife.bind(this, itemView);
      ViewUtils.setLayoutParams(layout, ScreenUtil.getWidth(), LayoutParams.WRAP_CONTENT);
    }

    @Override
    protected void bindData(ListBean data) {
      if (null == data || Util.listIsNull(data.reserveInfoDtoList)) {
        ViewUtils.setVisible(layout, false);
        return;
      }
      CommonAdapter<ReserveInfo> adapter = new CommonAdapter<ReserveInfo>(context,
          R.layout.include_statistics_book_header_msg,
          data.reserveInfoDtoList) {
        @Override
        protected void convert(ViewHolder holder, ReserveInfo bean, int position) {
          if (null == bean) {
            return;
          }
          holder.setText(R.id.tv_date, DateUtil.stampToDate(bean.reserveTime))
              .setText(R.id.tv_state, Util.isEquals(bean.come, true) ? "已到场" : "未到场")
              .setVisible(R.id.tv_state, !Util.isNull(bean.come))
              .setText(R.id.tv_teetime, TextUtil.Text(bean.playTime))
              .setText(R.id.tv_hole, TextUtil.textNumInt(bean.openBallCave) + "洞")
              .setText(R.id.tv_name, TextUtil.Text(bean.name))
              .setText(R.id.tv_id, TextUtil.Text(bean.identify))
              .setText(R.id.tv_worker, TextUtil.Text(bean.operator))
              .setVisible(R.id.ll_layout_nogroup, !OrderManager.isGroupOrder(orderType))
              .setVisible(R.id.ll_include_group_header_layout, OrderManager.isGroupOrder(orderType))
              .setText(R.id.tv_group_playtime, TextUtil.Text(bean.playTime))
              .setText(R.id.tv_group_holenum, TextUtil.Text(bean.openBallCave))
              .setText(R.id.tv_group_groupName, TextUtil.Text(bean.groupName))
              .setText(R.id.tv_group_playernum, TextUtil.textNumInt(bean.person))
              .setText(R.id.tv_group_userName, TextUtil.Text(bean.name))
              .setText(R.id.tv_group_id, TextUtil.Text(bean.identify))
              .setText(R.id.tv_group_tel, TextUtil.Text(bean.phone));

        }
      };
      LinearLayoutManager lm = new LinearLayoutManager(context);
      lm.setOrientation(LinearLayoutManager.VERTICAL);
      recyclerView.addItemDecoration(new RecyclerItemDecoration(1, 0, 0, 0));
      recyclerView.setLayoutManager(lm);
      recyclerView.setHasFixedSize(true);
      recyclerView.setAdapter(adapter);
    }
  }

  /**
   * teetime信息详情
   */
  public class TeetimeDetailsHolder extends Holder {

    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.ll_bar)
    View barView;
    @BindView(R.id.iv_arrow)
    ImageView arrowIv;
    @BindView(R.id.recycleView)
    RecyclerView recyclerView;

    public TeetimeDetailsHolder(View itemView) {
      super(itemView);
      ButterKnife.bind(this, itemView);
      ViewUtils.setLayoutParams(layout, ScreenUtil.getWidth(), LayoutParams.WRAP_CONTENT);
    }

    @Override
    protected void bindData(ListBean data) {
      if (null == data || Util.listIsNull(data.teeTimeDtoList)) {
        ViewUtils.setVisible(layout, false);
        return;
      }
      ViewUtils.setClick(barView, v -> {
        if (recyclerView.getVisibility() == View.VISIBLE) {
          ViewUtils.setVisible(recyclerView, false);
          ViewUtils.setImage(arrowIv, R.mipmap.arrow_right_grey);
        } else {
          ViewUtils.setVisible(recyclerView, true);
          ViewUtils.setImage(arrowIv, R.mipmap.arrow_down_grey);
        }
      });
      List<Teetime> list = new ArrayList<>();
      list.add(new ListBean().getTeetime());
      list.addAll(data.teeTimeDtoList);
      CommonAdapter<ListBean.Teetime> adapter = new CommonAdapter<Teetime>(context,
          R.layout.item_statistics_details_teetime, list) {
        @Override
        protected void convert(ViewHolder holder, Teetime bean, int position) {
          if (null == bean) {
            return;
          }
          if (position == 0) {
            holder.setText(R.id.tv_teetime, "Teetime")
                .setText(R.id.tv_hole, "洞数")
                .setText(R.id.tv_caddie, "球僮")
                .setText(R.id.tv_car, "球车")
                .setTextColor(R.id.tv_teetime, ContextCompat.getColor(context, R.color.text_blue2))
                .setTextColor(R.id.tv_hole, ContextCompat.getColor(context, R.color.text_blue2))
                .setTextColor(R.id.tv_caddie, ContextCompat.getColor(context, R.color.text_blue2))
                .setTextColor(R.id.tv_car, ContextCompat.getColor(context, R.color.text_blue2));
            return;
          }
          holder.setText(R.id.tv_teetime, TextUtil.Text(bean.teeTime, TextUtil.TAGNULL))
              .setText(R.id.tv_hole, TextUtil.Text(bean.openBallCave, TextUtil.TAGNULL))
              .setText(R.id.tv_caddie, TextUtil.Text(bean.caddie, TextUtil.TAGNULL))
              .setText(R.id.tv_car, new StringBuilder()
                  .append(TextUtil.Text(bean.coursecarnumber))
                  .append(Util.isNull(bean.coursecarnumber) ? TextUtil.TAGNULL : "号车")
                  .toString())
              .setTextColor(R.id.tv_teetime, ContextCompat.getColor(context, R.color.text_gray))
              .setTextColor(R.id.tv_hole, ContextCompat.getColor(context, R.color.text_gray))
              .setTextColor(R.id.tv_caddie, ContextCompat.getColor(context, R.color.text_gray))
              .setTextColor(R.id.tv_car, ContextCompat.getColor(context, R.color.text_gray));
        }
      };
      LinearLayoutManager lm = new LinearLayoutManager(context);
      lm.setOrientation(LinearLayoutManager.VERTICAL);
      recyclerView.setLayoutManager(lm);
      recyclerView.setHasFixedSize(true);
      recyclerView.setAdapter(adapter);
    }
  }

  /**
   * 开单信息详情
   */
  public class BillDetailsHolder extends Holder {

    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.tv_name)
    TextView nameTv;
    @BindView(R.id.iv_arrow)
    ImageView arrowIv;
    @BindView(R.id.ll_bar)
    View barView;
    @BindView(R.id.recycleView)
    RecyclerView recyclerView;
    @BindView(R.id.tv_money)
    TextView moneyTv;

    public BillDetailsHolder(View itemView) {
      super(itemView);
      ButterKnife.bind(this, itemView);
      ViewUtils.setLayoutParams(layout, ScreenUtil.getWidth(), LayoutParams.WRAP_CONTENT);
      ViewUtils.setText(nameTv, "开单明细");
    }

    @Override
    protected void bindData(ListBean data) {
      if (null == data) {
        ViewUtils.setVisible(layout, false);
        return;
      }
      ViewUtils.setClick(barView, v -> {
        if (recyclerView.getVisibility() == View.VISIBLE) {
          ViewUtils.setVisible(recyclerView, false);
          ViewUtils.setVisible(moneyTv, false);
          ViewUtils.setImage(arrowIv, R.mipmap.arrow_right_grey);
        } else {
          ViewUtils.setVisible(recyclerView, true);
          ViewUtils.setVisible(moneyTv, true);
          ViewUtils.setImage(arrowIv, R.mipmap.arrow_down_grey);
        }
      });
      if (mType == DataManager.STATISTICS_BILL_ALL) {
        if (Util.listIsNull(data.consumerItems)) {
          ViewUtils.setVisible(layout, false);
        } else {
          showBillDetails(data, recyclerView, moneyTv);
        }
        return;
      }
      if (Util.listIsNull(data.customerItemInfoDtoList)) {
        ViewUtils.setVisible(layout, false);
        return;
      }
      List<CustomerItemInfo> list = new ArrayList<>();
      list.add(new ListBean().getCustomerItemInfo());
      list.addAll(data.customerItemInfoDtoList);
      CommonAdapter<CustomerItemInfo> adapter
          = new CommonAdapter<CustomerItemInfo>(context, R.layout.item_goods_details, list) {
        @Override
        protected void convert(ViewHolder holder, CustomerItemInfo bean, int position) {
          if (null == bean) {
            return;
          }
          if (position == 0) {
            holder.setText(R.id.tv_teetime, "商品名称")
                .setText(R.id.tv_hole, "开单地点")
                .setText(R.id.tv_caddie, "数量")
                .setText(R.id.tv_car, "应付金额")
                .setTextColor(R.id.tv_teetime, ContextCompat.getColor(context, R.color.text_blue2))
                .setTextColor(R.id.tv_hole, ContextCompat.getColor(context, R.color.text_blue2))
                .setTextColor(R.id.tv_caddie, ContextCompat.getColor(context, R.color.text_blue2))
                .setTextColor(R.id.tv_car, ContextCompat.getColor(context, R.color.text_blue2));
            return;
          }
          holder.setText(R.id.tv_teetime, TextUtil.Text(bean.goodName))
              .setText(R.id.tv_hole, TextUtil.Text(bean.orderPlace))
              .setText(R.id.tv_caddie, TextUtil.textNumInt(bean.count))
              .setText(R.id.tv_car, new StringBuilder()
                  .append("￥")
                  .append(TextUtil.textNumFloat(bean.payable))
                  .toString())
              .setTextColor(R.id.tv_teetime, ContextCompat.getColor(context, R.color.text_gray))
              .setTextColor(R.id.tv_hole, ContextCompat.getColor(context, R.color.text_gray))
              .setTextColor(R.id.tv_caddie, ContextCompat.getColor(context, R.color.text_gray))
              .setTextColor(R.id.tv_car, ContextCompat.getColor(context, R.color.text_gray));

        }
      };
      ViewUtils.setVisible(moneyTv, true);
      int money = 0;
      for (int i = 0; i < data.customerItemInfoDtoList.size(); i++) {
        money += TypeUtil.parseFloat(data.customerItemInfoDtoList.get(i).payable);
      }
      ViewUtils.setText(moneyTv, "总金额 ￥" + money);
      LinearLayoutManager lm = new LinearLayoutManager(context);
      lm.setOrientation(LinearLayoutManager.VERTICAL);
      recyclerView.setLayoutManager(lm);
      recyclerView.setHasFixedSize(true);
      recyclerView.setAdapter(adapter);
    }
  }

  private void showBillDetails(ListBean data, RecyclerView recyclerView, TextView moneyTv) {

    List<GoodsBean> listData = new ArrayList<>();
    listData.add(new GoodsBean());
    listData.addAll(data.consumerItems);
    CommonAdapter<GoodsBean> adapter
        = new CommonAdapter<GoodsBean>(context, R.layout.item_goods_details, listData) {
      @Override
      protected void convert(ViewHolder holder, GoodsBean bean, int position) {
        if (null == bean) {
          return;
        }
        if (position == 0) {
          holder.setText(R.id.tv_teetime, "商品名称")
              .setText(R.id.tv_hole, "开单地点")
              .setText(R.id.tv_caddie, "数量")
              .setText(R.id.tv_car, "应付金额")
              .setTextColor(R.id.tv_teetime, ContextCompat.getColor(context, R.color.text_blue2))
              .setTextColor(R.id.tv_hole, ContextCompat.getColor(context, R.color.text_blue2))
              .setTextColor(R.id.tv_caddie, ContextCompat.getColor(context, R.color.text_blue2))
              .setTextColor(R.id.tv_car, ContextCompat.getColor(context, R.color.text_blue2));
          return;
        }
        holder.setText(R.id.tv_teetime, TextUtil.Text(bean.goodsName))
            .setText(R.id.tv_hole, TextUtil.Text(bean.orderPlace))
            .setText(R.id.tv_caddie, TextUtil.textNumInt(bean.consumeNumber))
            .setText(R.id.tv_car, new StringBuilder()
                .append("￥")
                .append(TextUtil.textNumFloat(bean.payable))
                .toString())
            .setTextColor(R.id.tv_teetime, ContextCompat.getColor(context, R.color.text_gray))
            .setTextColor(R.id.tv_hole, ContextCompat.getColor(context, R.color.text_gray))
            .setTextColor(R.id.tv_caddie, ContextCompat.getColor(context, R.color.text_gray))
            .setTextColor(R.id.tv_car, ContextCompat.getColor(context, R.color.text_gray));

      }
    };
    ViewUtils.setVisible(moneyTv, true);
    int money = 0;
    for (int i = 0; i < data.consumerItems.size(); i++) {
      money += TypeUtil.parseFloat(data.consumerItems.get(i).payable);
    }
    ViewUtils.setText(moneyTv, "总金额 ￥" + money);
    LinearLayoutManager lm = new LinearLayoutManager(context);
    lm.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(lm);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(adapter);
  }

  /**
   * 支付信息详情
   */
  public class PayDetailsHolder extends Holder {

    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.recycleView)
    RecyclerView recyclerView;
    @BindView(R.id.topline)
    View topLine;

    public PayDetailsHolder(View itemView) {
      super(itemView);
      ButterKnife.bind(this, itemView);
      ViewUtils.setLayoutParams(layout, ScreenUtil.getWidth(), LayoutParams.WRAP_CONTENT);
      ViewUtils.setVisible(topLine, true);
    }

    @Override
    protected void bindData(ListBean data) {
      if (null == data) {
        ViewUtils.setVisible(layout, false);
        return;
      }
      if (mType == DataManager.STATISTICS_BILL_ALL) {
        ViewUtils.setVisible(layout, !Util.listIsNull(data.cashWays));
        showBillPayInfo(data, recyclerView);
        return;
      }
      if (Util.listIsNull(data.payInfoDtoList)) {
        ViewUtils.setVisible(layout, false);
        return;
      }
      CommonAdapter<PayInfo> adapter = new CommonAdapter<PayInfo>(context, R.layout.item_pay_info,
          data.payInfoDtoList) {
        @Override
        protected void convert(ViewHolder holder, PayInfo bean, int position) {
          if (null == bean) {
            return;
          }
          holder.setText(R.id.tv_date, DateUtil.stampToDate(bean.cashTime))
              .setText(R.id.tv_payway, TextUtil.Text(bean.payType))
              .setText(R.id.tv_cardnum, TextUtil.Text(bean.cardNo, TextUtil.TAGNULL))
              .setText(R.id.tv_username, TextUtil.Text(bean.cashPerson))
              .setText(R.id.tv_money, new StringBuilder()
                  .append("￥")
                  .append(TextUtil.textNumFloat(bean.amount))
                  .toString());

        }
      };
      LinearLayoutManager lm = new LinearLayoutManager(context);
      lm.setOrientation(LinearLayoutManager.VERTICAL);
      recyclerView.addItemDecoration(new RecyclerItemDecoration(1, 0, 0, 0));
      recyclerView.setLayoutManager(lm);
      recyclerView.setHasFixedSize(true);
      recyclerView.setAdapter(adapter);


    }
  }

  private void showBillPayInfo(ListBean data, RecyclerView recyclerView) {
    if (Util.listIsNull(data.cashWays)) {
      return;
    }
    CommonAdapter<CashWay> adapter = new CommonAdapter<CashWay>(context, R.layout.item_pay_info,
        data.cashWays) {
      @Override
      protected void convert(ViewHolder holder, CashWay bean, int position) {
        if (null == bean) {
          return;
        }
//        try {
        holder.setVisible(R.id.ll_date, false)
            .setText(R.id.tv_holder_tag, TextUtil.Text("持卡人"))
            .setVisible(R.id.ll_bar, position == 0)
            .setText(R.id.tv_payway, TextUtil.Text(bean.cashWay))
            .setText(R.id.tv_cardnum, !Util.listIsNull(bean.items) ?
                TextUtil.Text(bean.items.get(0).tailNumber, TextUtil.TAGNULL)
                : TextUtil.TAGNULL)
            .setText(R.id.tv_username, !Util.listIsNull(bean.items) ?
                TextUtil.Text(bean.items.get(0).cardholder, TextUtil.TAGNULL)
                : TextUtil.TAGNULL)
            .setText(R.id.tv_money, new StringBuilder()
                .append("￥")
                .append(TextUtil.textNumFloat(bean.cost))
                .toString());
//        } catch (Exception e) {
//
//        }

      }
    };
    LinearLayoutManager lm = new LinearLayoutManager(context);
    lm.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(lm);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(adapter);
  }

  /**
   * 备注
   */
  public class RemarkHolder extends Holder {

    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.topline)
    View topLine;
    @BindView(R.id.tv_remark)
    TextView remarkTv;

    public RemarkHolder(View itemView) {
      super(itemView);
      ButterKnife.bind(this, itemView);
      ViewUtils.setLayoutParams(layout, ScreenUtil.getWidth(), LayoutParams.WRAP_CONTENT);
      ViewUtils.setVisible(topLine, mType != DataManager.STATISTICS_CADDIE_ALL);
    }

    @Override
    protected void bindData(ListBean data) {
      if (null == data) {
        ViewUtils.setText(remarkTv, "暂无备注信息");
        return;
      }
      if (mType == DataManager.STATISTICS_BOOK_ALL ||
          mType == DataManager.STATISTICS_BILL_ALL) {
        ViewUtils.setText(remarkTv, TextUtil.Text(data.remark, "暂无备注信息"));
        return;
      }
      ViewUtils.setText(remarkTv, null == data.customerInfoDto ?
          "暂无备注信息" : data.customerInfoDto.remark);
    }
  }

}
